package filters

import (
	"gateway/lib"
	"gateway/conf"
	"github.com/valyala/fasthttp"
	"gateway/types"
)
func NewFilterAcl() *FilterAcl{
	return &FilterAcl{}
}
type FilterAcl struct{

}
func (fa *FilterAcl)Pre(proxyContext *types.ProxyContext,fasthttpCtx *fasthttp.RequestCtx)(bool,int,string){
	acctoken := proxyContext.GetToken()
	cache := lib.NewCache()
	if chk,_ := cache.GetAclCheck(proxyContext.Mapkey);chk == "true"{
		return true,0,""
	}
	if acctoken == "" {
		return false, conf.REQUEST_INVALID_ACCESS_TOKEN,"access_token参数缺失"
	}
	application,err := proxyContext.GetAppInfo()
	if err != nil {
		return false, conf.REQUEST_INVALID_ACCESS_TOKEN,"令牌(access_token)无效"
	}else{
		//redis存有权限记录
		if v,_ := cache.GetAcl(application.Appid+"_"+proxyContext.Mapkey);v == "true" {
			return true, 0, ""
		}
	}
	return false, conf.REQUEST_NO_PERMISSION,"您无权限访问此接口"
}
func (fa *FilterAcl)Post(ctx *types.ProxyContext,fasthttpCtx *fasthttp.RequestCtx)(bool,int,string){
	return true, 0 ,""
}
